﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace GrayParrot.RabbitMQ.Configuration
{
    [ConfigurationCollection(typeof(Endpoint))]
    public class Endpoints : ConfigurationElementCollection
    {
        internal const string PropertyName = "Endpoint";

        [ConfigurationProperty("default", IsRequired = true, IsKey = false)]
        public string Default
        {
            get { return (string)base["default"]; }
            set { base["default"] = value; }
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.BasicMapAlternate;
            }
        }
        protected override string ElementName
        {
            get
            {
                return PropertyName;
            }
        }

        protected override bool IsElementName(string elementName)
        {
            return elementName.Equals(PropertyName, StringComparison.InvariantCultureIgnoreCase);
        }

        public override bool IsReadOnly()
        {
            return false;
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new Endpoint();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((Endpoint)(element)).Name;
        }

        public Endpoint this[string name]
        {
            get { return (Endpoint)BaseGet(name); }
        }
    }
}
